﻿using System;
using System.Linq;

namespace Xms.Abp.BackgroundJob;

public class BackgroundJobConfiguration
{
    public Type ArgsType { get; }

    public Type JobType { get; }

    public string JobName { get; }

    public string DisplayName { get; set; }

    public BackgroundJobConfiguration(Type jobType)
    {
        JobType = jobType;
        var attr = jobType.GetCustomAttributes(true)
                   .OfType<IBackgroundJobNameProvider>()
                   .FirstOrDefault();
        ArgsType = BackgroundJobArgsHelper.GetJobArgsType(jobType);
        JobName = attr?.Name ?? jobType.FullName;
        DisplayName = attr?.DisplayName ?? jobType.Name;
    }
}
